#include "SquirrelFuncs.h"
#include "Functions/SQMircFuncs.h"

SQInteger CSquirrelFuncs::RegisterGlobalFunc( HSQUIRRELVM v, SQFUNCTION f, const char *fname )
 {
        sq_pushroottable(v);
        sq_pushstring(v,fname,-1);
        sq_newclosure(v,f,0); //create a new function
        sq_createslot(v,-3);
        sq_pop(v,1); //pops the root table
        return 0;
 }

void CSquirrelFuncs::RegisterFuncs( HSQUIRRELVM v )
{
	sqstd_register_iolib( v );
	sqstd_register_mathlib( v );
	sqstd_register_bloblib( v );
	// sqstd_register_systemlib( v ); // This could be dangerous!
	sqstd_register_stringlib( v );

	RegisterGlobalFunc( v, CSQMircFuncs::Echo, "Echo" );
	RegisterGlobalFunc( v, CSQMircFuncs::Say, "Say" );
	RegisterGlobalFunc( v, CSQMircFuncs::Halt, "Halt" );
	RegisterGlobalFunc( v, CSQMircFuncs::Msg, "Msg" );
	RegisterGlobalFunc( v, CSQMircFuncs::Describe, "Action" );
	RegisterGlobalFunc( v, CSQMircFuncs::AMsg, "AMsg" );
	RegisterGlobalFunc( v, CSQMircFuncs::AMe, "AMe" );
	RegisterGlobalFunc( v, CSQMircFuncs::Nick, "Nick" );
	RegisterGlobalFunc( v, CSQMircFuncs::ANick, "ANick" );
	RegisterGlobalFunc( v, CSQMircFuncs::Join, "Join" );
	RegisterGlobalFunc( v, CSQMircFuncs::Part, "Part" );
	RegisterGlobalFunc( v, CSQMircFuncs::Kick, "Kick" );
	RegisterGlobalFunc( v, CSQMircFuncs::Ban, "Ban" );
}